#ifndef __CONTROLLER_H__
#define __CONTROLLER_H__

/* RF */
#define RF_RCC                      RCC_APB2Periph_GPIOC
#define RF_PORT                     GPIOC
#define RF_EXTI_PORT_SOURCE         GPIO_PortSourceGPIOC
#define RF_EXTI_IRQn                EXTI9_5_IRQChannel
#define rf_isr_handler              EXTI9_5_IRQHandler

#define RF_A_PIN                    GPIO_Pin_6
#define RF_A_EXTI_LINE              EXTI_Line6
#define RF_A_EXTI_PIN_SOURCE        GPIO_PinSource6

#define RF_B_PIN                    GPIO_Pin_7
#define RF_B_EXTI_LINE              EXTI_Line7
#define RF_B_EXTI_PIN_SOURCE        GPIO_PinSource7

#define RF_C_PIN                    GPIO_Pin_5
#define RF_C_EXTI_LINE              EXTI_Line5
#define RF_C_EXTI_PIN_SOURCE        GPIO_PinSource5

#define RF_D_PIN                    GPIO_Pin_8
#define RF_D_EXTI_LINE              EXTI_Line8
#define RF_D_EXTI_PIN_SOURCE        GPIO_PinSource8

/* On-board Buttons */
#define BUTTON_RCC                  RCC_APB2Periph_GPIOC
#define BUTTON_PORT                 GPIOC
#define BUTTON_EXTI_PORT_SOURCE     GPIO_PortSourceGPIOC
#define BUTTON_EXTI_IRQn            EXTI15_10_IRQChannel
#define button_isr_handler          EXTI15_10_IRQHandler

#define LEFT_PIN                    GPIO_Pin_5
#define LEFT_EXTI_LINE              EXTI_Line5
#define LEFT_EXTI_PIN_SOURCE        GPIO_PinSource5

#define CENTER_PIN                  GPIO_Pin_5
#define CENTER_EXTI_LINE            EXTI_Line5
#define CENTER_EXTI_PIN_SOURCE      GPIO_PinSource5

#define RIGHT_PIN                   GPIO_Pin_5
#define RIGHT_EXTI_LINE             EXTI_Line5
#define RIGHT_EXTI_PIN_SOURCE       GPIO_PinSource5


enum xbutton_id {
    LEFT     = 0,
    RIGHT    = 1,
    CENTER   = 2,
    OK       = 3
};

struct button_status_t {
    unsigned char left;
    unsigned char center;
    unsigned char right;
    unsigned char rf_a;
    unsigned char rf_b;
    unsigned char rf_c;
    unsigned char rf_d;
};

typedef void (*event_button_t)(enum xbutton_id button, void *data);
struct xcontroller {
    enum xbutton_id button;
    event_button_t button_handler;
};

#ifdef __cplusplus
extern "C" {
#endif

extern void controller_open( struct xcontroller *controller );
extern struct button_status_t get_button_state(void);
extern void register_callback(event_button_t callback);
#ifdef __cplusplus
}
#endif
#endif